package org.hadoop.controller;

import org.hadoop.dao.HiveDao;
import org.hadoop.entity.Student;
import org.hadoop.entity.TitleHot;
import org.hadoop.service.TitleHotService;
import org.hadoop.vo.AgentQueryVo;
import org.hadoop.vo.TitleCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;
@CrossOrigin//允许跨域
@RestController//返回数据
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private HiveDao hiveDao;

    @Autowired
    private TitleHotService titleHotService;

    @RequestMapping("/students")//localhost:8080/home/students
    public List<Student> getStudents() throws SQLException {
        return hiveDao.Students();
    }

    @RequestMapping("/count")
    public List<TitleHot> countByAgentAndTimeStamp(@RequestBody AgentQueryVo agentQueryVo) throws Exception {

        return titleHotService.countByAgentTimeStamp(agentQueryVo.getAgent(),agentQueryVo.getStart(),agentQueryVo.getEnd());
    }

    /**
     * 分别统计标题的热度
     * @return
     * @throws Exception
     */
    @RequestMapping("/hotsgroup")
    public List<TitleCount> hotsgroup() throws Exception {
        return titleHotService.findTitleCountByTimeStamp(0,System.currentTimeMillis());
    }
}
